//
//  assetsAViewController.m
//  ChinaA
//
//  Created by Mxionlly on 2018/11/5.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "assetsAViewController.h"
#import "assetsOrderViewController.h"
#import "MeCommunityViewController.h"
#import "walletViewController.h"
#import "QianBaoChongViewController.h"
#import "AssetsListTableViewCell.h"
#import "QianBaoTiViewController.h"
#import <Masonry.h>
#import "taskOverviewService.h"
#import <MJExtension.h>
#import "UILabel+LineSpace.h"

@interface assetsAViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)    UITableView *tableView;
@property (nonatomic,strong)    NSArray     *cellArray;
@property (nonatomic,strong)dataOverCoinInfo *coinModel;
@end

@implementation assetsAViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
    self.cellArray = @[@[@"收款",@"转账",@"交易订单",@"我的社区",@"china-A可用钱包",@"china-A冻结钱包",@"china-A分期冻结钱包",@"今日分润受益：0.00"],@[@"icon_ass_1",@"icon_ass_2",@"icon_ass_3",@"icon_ass_4",@"",@"",@"",@""]];
    [self loginIfSuccess];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self loginIfSuccess];
}

//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginIfSuccess) name:Notification_login_ok_notice object:nil];
//    }
//    return self;
//}


#pragma mark - load Data

-(void)loginIfSuccess
{
    [taskOverviewService getUserBurseCoinNumber:nil success:^(dataOverCoinInfoList *response, BOOL success) {
        if (success) {
            self.coinModel = [dataOverCoinInfo mj_objectWithKeyValues:response.data];
            [self.tableView reloadData];
        }
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

#pragma mark - loadtableview
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-246) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor whiteColor];
        _tableView.userInteractionEnabled = YES;
    }
    return _tableView;
}

#pragma mark - UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 4) {
        return 50;
    }
    return 60;
}

//AssetsTableViewCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 4) {
        AssetsListTableViewCell *cell = [AssetsListTableViewCell cellWithTableView:tableView];
        cell.rightImage.hidden = YES;
        cell.lbtitle.text = self.cellArray[0][indexPath.row];
        cell.iamgeView.image = [UIImage imageNamed:self.cellArray[1][indexPath.row]];
        return cell;
    }else{
        AssetsListTableViewCell *cell = [AssetsListTableViewCell cellWithTableView1:tableView];
        cell.lbtitle.text = self.cellArray[0][indexPath.row];
        cell.lbcontent.textColor = COLOR_main;
        if (indexPath.row == 4) {
            cell.lbcontent.text = [NSString stringWithFormat:@"%.2f",[self.coinModel.AvailableBurseCoinNumber floatValue]];
        }else if (indexPath.row == 5) {
            cell.lbcontent.text = [NSString stringWithFormat:@"%.2f",[self.coinModel.FreezeBurseCoinNumber floatValue]];
        }else if (indexPath.row == 6) {
            cell.lbcontent.text = [NSString stringWithFormat:@"%.2f",[self.coinModel.StagingFreezeBurseCoinNumber floatValue]];
        }else if (indexPath.row == 7) {
            if (self.coinModel.ShareCoinNumber.length > 0) {
                cell.lbtitle.text = @"";
                cell.lbtitle.setupmoreColorFont(@"今日分润受益:",[UIColor blackColor],14).setupmoreColorFont([NSString stringWithFormat:@"%.2f",[self.coinModel.ShareCoinNumber floatValue]],COLOR_main,14);
            }
            if (self.coinModel.GeneralizeCoinNumber.length > 0) {
                
                cell.lbcontent.setupmoreColorFont(@"社区推广受益:",[UIColor blackColor],14).setupmoreColorFont([NSString stringWithFormat:@"%.2f",[self.coinModel.GeneralizeCoinNumber floatValue]],COLOR_main,14);
            }
        }
        return cell;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        [self.navigationController pushViewController:[QianBaoChongViewController new] animated:YES];
    }else if (indexPath.row == 1){
        QianBaoTiViewController *vc = [[QianBaoTiViewController alloc]initWithNibName:@"QianBaoTiViewController" bundle:nil];
        vc.coinModel = self.coinModel;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        [self.navigationController pushViewController:[assetsOrderViewController new] animated:YES];
    }else if (indexPath.row == 3){
        [self.navigationController pushViewController:[MeCommunityViewController new] animated:YES];
    }else if (indexPath.row > 3 && indexPath.row < 7){
        walletViewController *detail = [walletViewController new];
        detail.available = indexPath.row - 4;
        [self.navigationController pushViewController:detail animated:YES];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
